<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>代码抽取系统</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-top: 50px;
        }
        button {
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
            margin-top: 20px;
        }
        #numbers {
            margin-top: 20px;
            font-size: 24px;
            font-weight: bold;
        }
        #qrcode {
            margin-top: 20px;
        }
    </style>
    <!-- 引入QRCode.js库 -->
    <script src="https://cdn.jsdelivr.net/npm/qrcode/build/qrcode.min.js"></script>
</head>
<body>
    <h1>代码抽取系统</h1>
    <button onclick="generateNumbers()">抽取代码</button>
    <div id="numbers"></div>
    <div id="qrcode"></div>

    <script>
        function generateNumbers() {
            let numbers = [];
            while (numbers.length < 4) {
                let randomNum = Math.floor(Math.random() * 10); // 随机生成0到9之间的数字
                if (!numbers.includes(randomNum)) {
                    numbers.push(randomNum);
                }
            }
            const numbersStr = numbers.join(' ');  // 将数字用空格分隔
            document.getElementById('numbers').textContent = '抽取的代码: ' + numbersStr;

            // 使用QRCode.js生成二维码并展示为img标签
            QRCode.toDataURL(numbersStr, function (error, url) {
                if (error) {
                    console.error(error);
                } else {
                    const qrImage = document.createElement('img');
                    qrImage.src = url;
                    document.getElementById('qrcode').innerHTML = ''; // 清空之前的二维码
                    document.getElementById('qrcode').appendChild(qrImage);
                }
            });
        }
    </script>
</body>
</html>
